package api;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionSortComparator {

	public static void main(String[] args) {
		List<Hotel> list = new ArrayList<Hotel>();
		list.add(new Hotel(3, "CESAR'S HERITAGE"));
		list.add(new Hotel(5, "CLEOPATRA PALACE"));
		list.add(new Hotel(4, "ANCIENT WONDER"));
		list.add(new Hotel(1, "THE HOUSE"));
		list.add(new Hotel(2, "SWEATODORIUM"));
		
		Collections.sort(list, new MyComaprator());
		for (Hotel hotel : list) {
			System.out.println(hotel);
		}
	}

	static class MyComaprator implements Comparator<Hotel> {

		@Override
		public int compare(Hotel o1, Hotel o2) {
			if (o1.getStars() > o2.getStars()) {
				return -1;
			}
			else if (o1.getStars() < o2.getStars()) {
				return 1;
			}
			else {
				return 0;
			}
		}

	}

	static class Hotel {

		private int stars;
		private String name;

		public Hotel(int stars, String name) {
			this.stars = stars;
			this.name = name;
		}

		public int getStars() {
			return stars;
		}

		public void setStars(int stars) {
			this.stars = stars;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		@Override
		public String toString() {
			return "Hotel [stars=" + stars + ", name=" + name + "]";
		}

	}

}
